// 储存类
class Storage {
    constructor () {
        this.loc = window.localStorage;
        this.ses = window.sessionStorage;
    }

    setItemS (key, value) {
        if (!key || key.length === 0) return 0;
        if (value && typeof value === 'object') {
            value = JSON.stringify(value);
        }
        this.ses.setItem(key, value);
    }

    getItemS (key) {
        const res = this.ses.getItem(key);
        try {
            return JSON.parse(res);
        } catch (err) {
            return res;
        }
    }

    setItemL (key, value) {
        if (!key || key.length === 0) return 0;
        if (value && typeof value === 'object') {
            value = JSON.stringify(value);
        }
        this.loc.setItem(key, value);
    }

    getItemL (key) {
        const res = this.loc.getItem(key);
        try {
            return JSON.parse(res);
        } catch (err) {
            return res;
        }
    }
}

export default new Storage();
